package com.xyd.Servlet;

import com.xyd.Biz.CommonTableBiz;
import com.xyd.Biz.Impl.CommonTableBizImpl;
import com.xyd.Entity.CommonTable;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/html/manage/SubmitAddCommonTableServlet")
public class SubmitAddCommonTableServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String parentId = request.getParameter("parentId");
        String className = request.getParameter("className");
        CommonTable commonTable = new CommonTable();


        CommonTableBiz commonTableBiz = new CommonTableBizImpl();


        if (Integer.parseInt(parentId) == 0) {
            commonTable.setType_char("OneTittle");
            commonTable.setType_name(className);
            commonTable.setType_value("Tittle" + className);
            commonTable.setVal_type(1);
            commonTableBiz.addCommonTable(commonTable);
            request.getRequestDispatcher("manage-result.jsp").forward(request,response);
        } else {
            commonTable.setType_char("TowTittle");
            commonTable.setType_name(className);
            commonTable.setType_value("T_"+className);
            commonTable.setOftype(commonTableBiz.getCommonTableById(Integer.parseInt(parentId)).getType_value());
            commonTable.setVal_type(1);
            commonTableBiz.addCommonTable(commonTable);
            request.getRequestDispatcher("manage-result.jsp").forward(request,response);
        }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
